#include"stdio.h"
#include"stdlib.h"

#define MAX 100
#define OK 1
#define ERROR 0
typedef int QlemType;
typedef int Stauts;

typedef struct {
	QlemType* base;
	int front;
	int rear;
}Queue;


Stauts InitQueue(Queue* Q)
{
	Q->base = (QlemType*)malloc(MAX * sizeof(QlemType));
	if (Q->base == NULL)
	{
		exit(ERROR);
	}
	Q->front = Q->rear = 0;
	return OK;
}

int QueueLenth(Queue Q)
{
	return (Q.rear - Q.front + MAX) % MAX;
}

Stauts PushQueue(Queue* Q, QlemType e)
{
	if ((Q->rear + 1) % MAX == Q->front)
		return ERROR;
	Q->base[Q->rear] = e;
	Q->rear = (Q->rear + 1) % MAX;
	return OK;
}

Stauts DeQueue(Queue* Q, QlemType* e)
{
	if (Q->front == Q->rear)
		return ERROR;
	*e = Q->base[Q->front];
	Q->front = (Q->front + 1) % MAX;
	return OK;
}


void GetHdad(Queue* Q, QlemType* e)
{
	if (Q->front == Q->rear)
		return;
	*e = Q->base[Q->front];
}


void ClearQueue(Queue* Q)
{
	Q->front = Q->rear = 0;
}


void DestroyQueue(Queue* Q)
{
	
	free(Q->base);
	Q->base = NULL;
}




